$(function () {
    let start=location.href.lastIndexOf('/');
    // console.log(start);
    let url = location.href.substring(start + 1);
    // console.log(url);
    // console.log($('#menu-posts'));
    if (url === 'posts.html' || url === 'categories.html' || url.startsWith('post-add.html')) {
        $('#menu-posts').removeClass('collapse');
    }
    if (url === 'navMenus.html' || url === 'slides.html' || url === 'settings.html'){
        $('#menu-settings').removeClass('collapse')
    }
    let avatar = localStorage.getItem('avatar');
    let nickname = localStorage.getItem('nickname');
    $('.aside .avatar').attr('src',avatar);
    $('.aside .name').text(nickname);

    // 点击退出
    $('#logout').on('click',function(){
        $.ajax({
            type:'get',
            url:'/admin/user/logout',
            success(res){
                if(res.code===200){
                    //  $('#logout').attr('src','')
                    location.href='/admin/user/login.html'
                }
            }
        })
    })
});